<?php

namespace plugin\muadmin\app\admin\controller\general;

use plugin\muadmin\app\common\base\BaseAdminController;
use plugin\muadmin\app\common\model\Admin;
use think\Model;

class Profile extends BaseAdminController
{
    public function index()
    {
        $userInfo = Admin::where('id',$this->auth->id)->withoutField('password,salt,username')->find();
        if($this->request->isAjax()){
            $data = $this->param('row');
            if(!empty($data['password'])){
                $data['password'] = create_password($data['password'],$userInfo->salt);
            }
            $res = $userInfo->save($data);
            if(!$res){
                return $this->error('保存失败');
            }
            return $this->success('保存成功',$data);
        }
        $this->assignConfig('user_info',$userInfo);
        return $this->fetch();
    }
}